﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhatPhucLoc.dao;
using PhatPhucLoc.model;

namespace PhatPhucLoc.view
{
    public partial class FormKhachHangSanPham : Form
    {
        private int flag = 0;
        public FormKhachHangSanPham()
        {
            InitializeComponent();
            LoadKH();
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            /*
            FormKhachHangSanPham formKhachHangSanPham = this;
            KhachHangModel model = new KhachHangModel();
            model.Ten =(String) cmbKH.SelectedItem.ToString();
            model.Id =cmbKH.SelectedValue.ToString();
            FormThemKhanhHangSanPham formThemKhanhHangSanPham = new FormThemKhanhHangSanPham(model, formKhachHangSanPham);
            formThemKhanhHangSanPham.ShowDialog();
            */
        }

        private void LoadKH()
        {
            DataTable dt = KhachHangDAO.KhachHang_GetAll();
            cmbKH.DataSource = dt;
            cmbKH.DisplayMember = "Ten";
            cmbKH.ValueMember = "ID";
            LoadHH();

        }

        private void LoadHH()
        {
            DataTable dt = KhachHang_HangHoaDAO.GetAll_ByID(cmbKH.SelectedValue.ToString());
            dataGridView1.DataSource = dt;
         }

        private void cmbKH_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(flag>0)
            {
                LoadHH();
            }
            flag++;
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            /*
            FormKhachHangSanPham frm = this;
            KhachHangSanPhamModel model = new KhachHangSanPhamModel();
            model.Id = dataGridView1.CurrentRow.Cells["Id"].Value.ToString(); 
            model.MaHH =dataGridView1.CurrentRow.Cells["MaHH"].Value.ToString();
            model.TenHH = dataGridView1.CurrentRow.Cells["TenHH"].Value.ToString();
            model.MaKH = dataGridView1.CurrentRow.Cells["MaKH"].Value.ToString();
            model.GiaBan = dataGridView1.CurrentRow.Cells["GiaTien"].Value.ToString();
            FormChiTietKhachHangSanPham formCTKHSP = new FormChiTietKhachHangSanPham( frm,model );
            formCTKHSP.ShowDialog();
            */
        }
    }
}
